package cn.aimee.permission.util.string;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil {

	public static boolean isEmpty(String str) {
		return null == str || str.trim().length() == 0;
	}

	public static boolean isNotEmpty(String s) {
		if (null != s && s.trim().length() > 0) {
			return true;
		}
		return false;
	}

	public static boolean isContainChinese(String str) {
		Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
		Matcher m = p.matcher(str);
		if (m.find()) {
			return true;
		}
		return false;
	}

	/**
	 * 字符串是否只包含中文、英文和数字
	 * @param str
	 * @return
	 */
	public static boolean isOnlyChineseOrEnglishOrNumber(String str) {
		Pattern pattern = Pattern.compile("[0-9a-zA-Z|\u4e00-\u9fa5]+");
		Matcher matcher = pattern.matcher(str);
		return matcher.matches();
	}

	/**
	 * 字符串是否只包含英文和数字
	 * @param str
	 * @return
	 */
	public static boolean isOnlyEnglishOrNumber(String str) {
		Pattern pattern = Pattern.compile("[0-9a-zA-Z]+");
		Matcher matcher = pattern.matcher(str);
		return matcher.matches();
	}

	/**
	 * 字符串是否只包含数字
	 * @param str
	 * @return
	 */
	public static boolean isOnlyNumber(String str) {
		Pattern pattern = Pattern.compile("[0-9]+");
		Matcher matcher = pattern.matcher(str);
		return matcher.matches();
	}

}